import requests
from flask import Flask, flash, url_for
from flask import template_rendered, request
from ORM import ORM
app = Flask(__name__)


@app.route("/")
def home():
    """
    打开网站第一页
    :return:
    """
    return template_rendered('home.html')


@app.route("/login/", methods=['GET', 'POST'])
def login():
    if request.method == "POST" and ORM.valid_login(request.form['username'], request.form['password']):
        return url_for(home)
    else:
        error = ("账号或者密码输入错误")
    return template_rendered('login.html', error=error)


@app.route("/regist/", methods= ['GET', 'POST'])
def regist():
    if request.method == 'POST':
        username = request.form.get('username')
        # 匹配两个密码是否相同,添加到数据库
        if request.form.get('password') == request.form.get('repassword'):
            pass
    else:
        flash("两次密码不一致")
        return template_rendered('register.html')


@app.route('/exit/')
def exit():
    pass

